<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
        </script>
        <script>
            function login() {
                var email = $("#email").val();
                var password = $("#password").val();
                $.ajax({
                    url: "http://localhost:9002/api/user/login/" + email + "/" + password,
                    type: "GET",
                    success: function (req) {
                        alert("cookie:" + req);
                        window.location.replace('welcome.html')
                    },
                    complete: function (xhr, data) {
                        /*
                            获取相关Http Response header
                            getResponseHeader(key)：获取指定头信息
                            getAllResponseHeaders()：获取全部可默认可获取的头信息
                        */
                        var token = xhr.getResponseHeader('example-token');
                        console.log('token: ', token);
                        localStorage.setItem("token", token);
                    },
                    error: function () {
                        alert("登录失败");
                    }
                });
            }

        </script>
        <title>登录</title>
    </head>
    <body>
        <form>
            邮箱
            <input id="email" type="text"/>
            <br/>
            密码
            <input id="password" type="password"/>
            <br/>
            <button type="button" onclick="login()">登录</button>
        </form>
        <a href="register.html">注册新账号</a>
    </body>
</html>